package com.qingcloud.adminbackend.mapper;

import com.qingcloud.adminbackend.entity.sysorder.SysOrderEquipment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qingcloud.adminbackend.entity.sysstation.SysStationEquipment;
import com.qingcloud.adminbackend.entity.equipment.EquipmentBO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 订单关联设备表 Mapper 接口
 * </p>
 *
 * @author liyuhong
 * @since 2019-01-02
 */
public interface SysOrderEquipmentMapper extends BaseMapper<SysOrderEquipment> {

    /**
     * 删除订单关联的设备
     *
     * @param orderId
     * @param equipmentIds
     */
    void deleteEquipmentsByIds(@Param("orderId") String orderId, @Param("equipmentIds") List<String> equipmentIds);

    /**
     * 订单关联设备Api(从设备池移入)
     *
     * @param equipmentDTOs
     */
    void orderToEquipment(@Param("equipmentDTOs") List<EquipmentBO> equipmentDTOs);

    /**
     * 删除订单关联的监测点
     *
     * @param equipmentDTOs
     */
    void deleteEquipmentsByStationIds(@Param("orderId") String orderId, @Param("equipmentDTOs") List<EquipmentBO> equipmentDTOs);

    /**
     * 删除订单设备表
     *
     * @param orderIds
     */
    void deleteOrderEquipment(@Param("orderIds") List<String> orderIds);

    /**
     * 订单下的设备
     *
     * @param orderId
     * @return
     */
    List<SysStationEquipment> findEquipmentsByOrderId(@Param("orderId") String orderId, @Param("equipmentIds") List<String> equipmentIds);

    /**
     * 订单下的监测点
     *
     * @param orderId
     * @return
     */
    List<String> findStationsByOrderId(@Param("orderId") String orderId, @Param("stationIds") List<String> stationIds);

    /**
     * 修改订单下的设备关系表
     *
     * @param orderId
     * @param stationId
     */
    void updateEquipmentsByIds(@Param("orderId") String orderId, @Param("stationId") String stationId);

    /**
     * 验证该设备或站点除此订单为是否还绑定别的订单
     *
     * @param orderId
     * @param equipmentIds
     * @return
     */
    List<String> verifyEquipmentOrderId(@Param("orderId") String orderId, @Param("equipmentIds") List<String> equipmentIds, @Param("stationIds") List<String> stationIds);

    /**
     * 删除只有设备的数据
     *
     * @param equipmentIds
     */
    void deleteStationgroupEquipmentsByIds(@Param("equipmentIds") List<String> equipmentIds);

    /**
     * 清空设备组下设备绑定关系
     *
     * @param stationId
     */
    void updateStationgroupEquipmentsByIds(@Param("stationId") String stationId);

    /**
     * 根据检测点编号查询订单编号
     *
     * @param stationId
     * @return
     */
    String findOrderIdByStationId(@Param("stationId") String stationId);

    /**
     * 根据设备编号查询订单编号
     *
     * @param equipmentId
     * @return
     */
    String findOrderIdByEquipmentId(@Param("equipmentId") String equipmentId);


    Integer deleteByBind(@Param("equipmentId") String equipmentId);

    /**
     * 刪除监测点和订单的关系
     * @param stationIds
     */
    void deleteOrderByStationId(@Param("stationIds") List<String> stationIds);

    /**
     * 验证设备是否绑定别的订单
     * @param orderId
     * @param equipmentIds
     * @return
     */
    List<String> findEquipmentsByNotOrderId(@Param("orderId") String orderId,@Param("equipmentIds") List<String> equipmentIds);
}
